﻿@{
    Layout = "~/Views/Shared/_Index.cshtml";
}
<link href="~/plugins/zTree_v3/css/bootstrapStyle/bootstrapStyle.css" rel="stylesheet" />
<div class="ibox">
    <div class="ibox-content">
        <form class="form form-horizontal" id="form" autocomplete="off">
            <input type="hidden" name="id" id="id" value="@(ViewBag.Id)">
            <div class="form-group">
                <label class="col-sm-3 control-label required">用户名：</label>
                <div class="col-sm-4">
                    <input type="text" name="account_name" id="account_name" value="" class="form-control" data-rule="required" readonly="readonly">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label required">姓名：</label>
                <div class="col-sm-4">
                    <input type="text" name="real_name" id="real_name" value="" class="form-control" data-rule="required">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label required">密码：</label>
                <div class="col-sm-4">
                    <input type="password" name="pass_word" id="pass_word" class="form-control" data-rule="密码:required;password;">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label required">确认密码：</label>
                <div class="col-sm-4">
                    <input type="password" name="SurePassWord" id="SurePassWord" class="form-control" data-rule="确认密码:required;password;match(pass_word)">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">部门：</label>
                <div class="col-sm-4">
                    <textarea id="parentDept" style="width:300px;height:50px;overflow:hidden;" textLabel="jasontext" type="text" readonly></textarea>
                    <input type="hidden" name="dept_id" id="dept_id" value="0" class="form-control">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label ">联系方式：</label>
                <div class="col-sm-4">
                    <input type="text" name="mobile_phone" id="mobile_phone" class="form-control" data-rule="mobile;">
                </div>
            </div>
            <div class="form-group">
                <label class="col-sm-3 control-label">邮箱：</label>
                <div class="col-sm-4">
                    <input type="text" name="email" id="email" value="" class="form-control" data-rule="email;">
                </div>
            </div>
            <div class="hr-line-dashed"></div>
            <div class="form-group">
                <div class="col-sm-12 col-sm-offset-3">
                    <button class="btn btn-primary" type="submit">保存内容</button>
                    <button class="btn btn-white" type="button" onclick="cancel()">取消</button>
                </div>
            </div>
        </form>
    </div>

</div>
@section scripts{
    <script src="~/plugins/zTree_v3/js/jquery.ztree.all.min.js"></script>
    <script src="~/plugins/selectTree/MultipleTreeSelect.js"></script>
    <script type="text/javascript">

        $(function () {
            $('#form').validator({
                stopOnError: false,
                timely: 2,
                theme: "yellow_right",
                valid: function (form) {

                    // 表单验证通过，提交表单
                    jutils.ajaxPost('/admin/sysuser/UpdateProfile', $(form).serialize(),
                        function (res) {
                            jutils.closeForm();
                        });
                }
            });

            loadData();
        });


        function loadData() {
            var id = jutils.getQueryParam('id');
            jutils.ajaxGet('/admin/sysuser/GetUserById', { id: id }, function (res) {
                var model = res.data.model;
                $('#form').initFormData(model);
                $('#SurePassWord').val(model.pass_word);
                if (model.dept_id != 0) {
                    $('#parentDept').attr('checks', model.dept_id);
                }
                initSelectTree(res.data.depts);
            });
        }

        function initSelectTree(treeNodes) {
            var defaults = {
                callback: {
                    onCheck: zTreeOnCheck
                },
                chkStyle: "radio",
                zNodes: treeNodes,
                height: 333   // 默认自定义下拉框高度
            }

            $("#parentDept").drawMultipleTree(defaults);
        }
        function zTreeOnCheck(treeNodes) {
            // console.log(treeNodes);

            // alert(treeNode.tId + ", " + treeNode.name + "," + treeNode.checked);
            //selectDepartments.length = 0;
            if (treeNodes.length > 0) {
                var parentId = treeNodes[0].id;
                $('#dept_id').val(parentId);
            } else {
                $('#dept_id').val(0);
            }

            //console.log(selectDepartments);
        };
        function cancel() {
            jutils.closeForm();
        }
    </script>


}



